package com.tanhua.api.mongo;

import com.tanhua.domain.mongo.Comment;
import com.tanhua.domain.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class MessagesApiImpl implements MessagesApi {
    @Autowired
    private MongoTemplate mongoTemplate;
    //统计点赞 喜欢 评论
    public PageBeanVo findComment(Integer page, Integer pagesize, Long commentTypeId, Long id) {
        Query query = new Query(Criteria.where("publishUserId").is(id)
        .and("commentType").is(commentTypeId));
        query.skip((page-1)*pagesize).limit(pagesize);
        List<Comment> list = mongoTemplate.find(query, Comment.class);
        Long count = mongoTemplate.count(query, Comment.class);

        return new PageBeanVo(page,pagesize,count,list);
    }
}
